package com.lemon.smartsafety.ui.activity.safe.data.safe_manager;

import android.support.v4.app.Fragment;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.entity.event.safe_manager.SafeItemRefreshEvent;
import com.lemon.smartsafety.entity.safe.company.CompanyInfo;
import com.lemon.smartsafety.entity.safe.safe_manager.CompanySafeManageHistoryItemVo;
import com.lemon.smartsafety.entity.safe.safe_manager.CompanySafeManageItemVo;
import com.lemon.smartsafety.http.service.SafeManagerHistoryItemServices;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.adapter.safe.safe_manager.SafeManagerHistoryItemAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.common.LoggerHelper;

import org.greenrobot.eventbus.Subscribe;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

public class SafeManagerPropHistoryFragment extends BasePullToRefreshFragment<CompanySafeManageHistoryItemVo, List<CompanySafeManageHistoryItemVo>> implements RecyclerTClickListener<CompanySafeManageHistoryItemVo> {

    private LoggerHelper loggerHelper = new LoggerHelper(SafeManagerPropHistoryFragment.class);
    private CompanyInfo mCompanyInfo;
    private CompanySafeManageItemVo mSafeVo;

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();
        if (getArguments() != null) {
            mCompanyInfo = (CompanyInfo) getArguments().getSerializable(BundleKey.COMPANY_INFO);
            mSafeVo = (CompanySafeManageItemVo) getArguments().getSerializable(BundleKey.SAFE_MANAGER_ITEM);
        }
    }

    public static Fragment newInstance() {
        SafeManagerPropHistoryFragment fragment = new SafeManagerPropHistoryFragment();
        return fragment;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_safe_manager_prop_history;
    }

    @Override
    protected void initViews() {
        pageSize = 10;
        super.initViews();
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<CompanySafeManageHistoryItemVo> getLemonAdapter() {
        return new SafeManagerHistoryItemAdapter(getActivity(),mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return EventTag.TAG_SAFE_MANAGER_HISTORY;
    }

    @Override
    public void onPullRefresh() {
        SafeManagerHistoryItemServices.init().getItemList(RefreshType.REFRESH,mSafeVo.getItem_id(), pageSize, currentPage);
    }


    @Override
    public void onLoadMore() {
        SafeManagerHistoryItemServices.init().getItemList(RefreshType.LOAD_MORE,mSafeVo.getItem_id(), pageSize, currentPage);
    }

    /**
     * 刷新事件
     *
     * @param event
     */
    @Subscribe
    public void onEventMainThread(SafeItemRefreshEvent event) {
        if (SafeItemRefreshEvent.class.getName().equals(event.getTag())) {
            mPullToRefreshRecyclerView.beginRefreshing();
        }
    }

    @Override
    public void onItemClick(CompanySafeManageHistoryItemVo data, int position) {
    }
}
